home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctjmr86.arc
/
SPMMLIB.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-12-16
|
4KB
|
131 lines
{-------------------------------------------}
{ SUB-PROCESS AND MEMORY MANAGEMENT LIBRARY }
{-------------------------------------------}
type
r8086=
record
ax,bx,cx,dx,bp,di,si,ds,es,flags:integer;
end;
asciiz=string[65];
var regs:r8086;
{ ---------------- REDUCE MEMORY ALLOCATION }
function dos4AH(pp_to_release:integer):integer;
external 'dos4AH.com';
{-------------------- EXECUTE A SUB-PROCESS }
function dos4BH(var program_name,parameter_string):integer;
external 'dos4BH.com';
{--------------- ALLOCATE A NEW MEMORY BLOCK }
function dos48H(pp_needed:integer;var block_segment:integer):integer;
begin
regs.bx:=pp_needed; { # of paragraphs required. }
regs.ax:=$48 shl 8; { Function call 48H. }
msdos(regs); { Call DOS. }
if (regs.flags and 1)<>0 then { Is carry flag set? }
begin
block_segment:=regs.ax; { Yes, return available pp's, }
dos48h:=lo(regs.ax); { and error number. }
end
else
begin
block_segment:=regs.ax; { No, return segment address, }
dos48h:=0; { and error code 0 }
end;
end;
{--------------------- RELEASE A MEMORY BLOCK }
function dos49H(block_segment:integer):integer;
begin
regs.es:=block_segment; { Segment address to release. }
regs.ax:=$49 shl 8; { Function call 49H. }
msdos(regs); { Call DOS. }
if (regs.flags and 1)<>0 then { Is carry flag set? }
dos49H:=lo(regs.ax) { Yes, return error number. }
else
dos49H:=0; { No, return error code 0. }
end;
{---------------- OBTAIN A PROCESS'S EXIT CODE }
function dos4DH:integer;
begin
regs.ax:=$4d shl 8; { Function call 4DH. }
msdos(regs); { Call DOS. }
dos4dH:=lo(regs.ax); { Return Exit Code. }
end;
{--------------- GET COMMAND PROCESSOR NAME }
function get_comspec(var comspec:asciiz):boolean;
type
dos_env_type=array[1..254] of byte;
dos_env_string=^dos_env_type;
var
dos_env:dos_env_string;
dos_envs:string[255];
idx:integer;
begin
get_comspec:=false;
dos_env:=ptr(memw[cseg:$2c],$0); { Get 254 bytes of the DOS }
move(dos_env^,dos_envs[1],254); { environment string. }
dos_envs[255]:=#0;
dos_envs[0]:=#255;
idx:=pos('COMSPEC=',dos_envs); { Find COMSPEC= portion. }
if idx=0 then { Yikes! No COMSPEC= there! }
begin
writeln('*** "COMSPEC=d:[path]filename" not in DOS environment.');
get_comspec:=true;
exit; { Return TRUE. }
end
else
begin
delete(dos_envs,1,idx+7); { Isolate the ASCIIZ string }
idx:=pos(#0,dos_envs); { drive:[path]filename }
dos_envs:=copy(dos_envs,1,idx); { of the command processor.}
while dos_envs[1]=' ' do
delete(dos_envs,1,1);
comspec:=dos_envs; { Return FALSE. }
end;
end;
{----------------------- HANDLE A DOS ERROR CONDITION }
function dos_error_check(error_code:integer):boolean;
type
error_table_type = array [1..18] of string[41];
const
error_table: error_table_type = { RANGE: 1 TO 18 DECIMAL }
('Invalid function number',
'File not found',
'Path not found',
'Too many open files (no handles left)',
'Access Denied',
'Invalid file handle',
'Memory control blocks destroyed',
'Insufficient Memory',
'Invalid memory block address',
'Invalid environment',
'Invalid format',
'Invalid access code',
'Invalid data',
'UNRECOGNIZED ERROR', { NOT USED BY DOS }
'Invalid drive was specified',
'Attempted to remove the current directory',
'Not same device',
'No more files');
begin
dos_error_check:=true;
if error_code=0 then
dos_error_check:=false
else
writeln('*** DOS error ',error_code,': ',error_table[error_code]);
end;